﻿namespace CSharpLogger
{
    /// <summary>
    /// Implements <see cref="ILoggerHandlerFactory"/>
    /// </summary>
    /// <remarks>Factory Method: ConcreteCreator</remarks>
    public sealed class LoggerHandlerFactory : ILoggerHandlerFactory
    {
        /// <summary>
        /// Returns an instance of a class that implements the <see cref="ILoggerHandler"/> interface.
        /// </summary>
        /// <example>
        ///     <code>
        ///         var handler = new LoggerHandlerFactory();
        ///         var logger = handler.GetHandler<FileLogger>();
        ///     </code>
        /// </example>
        /// <returns><see cref="ILoggerHandler"/>.</returns>
        public T GetHandler<T>() where T : ILoggerHandler
        {
            var type = typeof(T);
            var instance = type.GetProperty("Logger");
            return (T)instance.GetValue(instance);
        }
    }
}
